package zjitc.servlet;

import zjitc.domain.User;
import zjitc.service.UserService;
import zjitc.service.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

@WebServlet("/userListServlet")
public class UserListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置编码
        request.setCharacterEncoding("utf-8");
        //调用service获取数据
        UserService service = new UserServiceImpl();
        List<User> users = service.findAll();
        //把数据保存在request域
        request.setAttribute("user",users);
        //跳转页面到List.jsp
        request.getRequestDispatcher("/list.jsp").forward(request,response);
    }
}
